package com.huike.clues.service.impl;


import com.huike.clues.domain.TbAssignRecord;
import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.clues.utils.HuiKeCrmDateUtils;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.unit.DataUnit;

import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {


    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;
    @Autowired
    private TbClueMapper tbClueMapper;


    /**
     * 新增线索跟进记录
     * @param tbClueTrackRecord
     * @return
     */
    @Override
    public int insertTbClueTrackRecord(ClueTrackRecordVo tbClueTrackRecord) {

        TbClue tbClue =new TbClue();
        tbClue.setId(tbClueTrackRecord.getClueId());
        BeanUtils.copyProperties(tbClueTrackRecord,tbClue);
        tbClueMapper.updateTbClue(tbClue);

        TbClueTrackRecord tbClueTrackRecord1=new TbClueTrackRecord();
        tbClueTrackRecord1.setClueId(tbClueTrackRecord.getClueId());
        tbClueTrackRecord1.setCreateBy(SecurityUtils.getUsername());
        tbClueTrackRecord1.setSubject(tbClueTrackRecord.getSubject());
        tbClueTrackRecord1.setRecord(tbClueTrackRecord.getRecord());
        tbClueTrackRecord1.setLevel(tbClueTrackRecord.getLevel());
        tbClueTrackRecord1.setType(tbClueTrackRecord.getType());
        tbClueTrackRecord1.setFalseReason(tbClueTrackRecord.getFalseReason());
        tbClueTrackRecord1.setNextTime(tbClueTrackRecord.getNextTime());
        int rows = tbClueTrackRecordMapper.insertTbClueTrackRecord(tbClueTrackRecord1);
        return rows;
    }


    /**
     * 查询线索跟进记录列表
     * @param clueId
     * @return
     */
    @Override
    public List<TbClueTrackRecord> selectTbClueTrackRecord(Long clueId) {
        return tbClueTrackRecordMapper.selectTbClueTrackRecord(clueId);
    }


}
